#include "rules_searcher.hpp"

namespace mashine { namespace kb { namespace search {

/**
 * create visitor that search facts with specified name
 * by default name = * (select all facts)
 */
RulesSearchVisitor::RulesSearchVisitor(std::string name)
		: SearchVisitor<mashine::kb::Rule, std::string>(new std::string(name))
{

}

/**
 * get array of facts selected from kBase
 */
std::vector<mashine::kb::Rule *> * RulesSearchVisitor::search(mashine::kb::KnowledgeBase * kBase)
{
	if (criteria->compare("*"))
	{
		return kBase->getRules();
	}

	std::vector<mashine::kb::Rule *> * result = new std::vector<mashine::kb::Rule *>();

	std::vector<mashine::kb::Rule *>::const_iterator i;
	for (i = kBase->getRules()->begin(); i != kBase->getRules()->end(); ++i)
	{
		if ( criteria->compare((*i)->getUndeniableLiteral()->getName()) )
		{
			result->push_back(*i);
		}
	}

	return result;
}

}}}
